/**
 * Copyright (c) 2006, PORTALIER Julien
 * 
 * Licensed under The LGPL License
 * Redistributions of files must retain the above copyright notice.
 * 
 * @copyright  Copyright (c) 2006, Julien PORTALIER
 * @link       http://feather-cm.googlecode.com/
 * @license    http://www.opensource.org/licenses/lgpl-license.php The LGPL License
 */

var Hideable = new Class(
{
	initialize: function(toggler, content, options)
	{
		this.toggler = $(toggler);
		this.content = $(content);
		this.options = {'className': 'hidden'};
		this.setOptions(options);
		
		this.toggler.addEvent('click', this.toggle.bind(this));
		this.toggle();
	},
	
	toggle: function()
	{
		if (this.content.getStyle('display') == 'none')
		{
			this.content.setStyle('display', '');
			this.toggler.removeClass(this.options.className);
		}
		else
		{
			this.toggler.addClass(this.options.className);
			this.content.setStyle('display', 'none');
		}
		
	}
});
Hideable.implement(new Options());

window.addEvent('domready', function()
{
	$ES('fieldset.hideable').each(function(fieldset) {
		new Hideable($E('legend', fieldset), $E('div', fieldset));
	});
});